//
//  Mine_NavBar.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "Mine_NavBar.h"

@interface Mine_NavBar ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UIButton *iconBtn;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *descLab;

@end

@implementation Mine_NavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, StatusBarHeight + 30, 60, 60)];
        self.iconImgView.layer.cornerRadius = 30;
        self.iconImgView.layer.masksToBounds = YES;
        self.iconImgView.backgroundColor = Color_Separator;
        self.iconImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:self.iconImgView];
        
        self.iconBtn = [[UIButton alloc] initWithFrame:self.iconImgView.frame];
        [self.iconBtn addTarget:self action:@selector(iconClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.iconBtn];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.nim_right + 15, self.iconImgView.nim_top + 8, ScreenW - 10 - (self.iconImgView.nim_right + 15), 19)];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = BoldFontOfSize(18);
        [self addSubview:self.titleLab];
        
        self.descLab = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.nim_right + 15, self.titleLab.nim_bottom + 10, ScreenW - 10 - (self.iconImgView.nim_right + 15), 15)];
        self.descLab.textColor = HexColor(0x2B2C44);
        self.descLab.font = BoldFontOfSize(14);
        [self addSubview:self.descLab];
    }
    return self;
}

- (void)iconClick {
    if (self.iconBlock) {
        self.iconBlock();
    }
}

-(void)setTitle:(NSString *)title {
    _title = title;
    self.titleLab.text = title;
}

-(void)setName:(NSString *)name {
    _name = name;
    self.descLab.text = name;
}

-(void)setIcon:(NSString *)icon {
    _icon = icon;
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:icon]];
}

@end
